<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数码时钟</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html, body {
            width: 100%;
            height: 100%;
        }

        .clock {
            position: relative;
            width: 400px;
            height: 300px;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }

        span {
            font-size: 34px;
        }
    </style>
</head>
<body>
<div class="clock">
    <span class="hour">00</span>时
    <span class="minute">00</span>分
    <span class="second">00</span>秒
</div>
<script>
    window.onload = function () {
        let hour = document.getElementsByTagName('span')[0];
        let minute = document.getElementsByTagName('span')[1];
        let second = document.getElementsByTagName('span')[2];

        setInterval(function () {
            let now = new Date();
            let h = now.getHours();
            let m = now.getMinutes();
            let s = now.getSeconds();

            // alert(h + ':' + m + ':' + s);

            if (h < 9) {
                h = '0' + h;
            }
            if (m < 9) {
                m = '0' + m;
            }
            if (s < 9) {
                s = '0' + s;
            }
            hour.innerText = h;
            minute.innerText = m;
            second.innerText = s;

        }, 1000);


    };


</script>
</body>
</html>